/*
 * RemoveRouteCommand.java
 *
 * Created on October 5, 2007, 5:59 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package drb;

import java.io.BufferedReader;
import java.sql.*;

/**
 *
 * @author Asger
 */
public class RemoveRouteCommand extends PromptingCommand {
    
    /** Creates a new instance of RemoveRouteCommand */
    public RemoveRouteCommand(BufferedReader input) {
        super(input);
    }
    
    public void execute() throws SQLException {
        // Get the route to remove
        ScheduleRoute route = promptScheduleRoute("Enter the starting station of the route you wish to remove: (No routes will be removed yet)",
                "Enter the Id of the route you wish to remove, from the list above. (You will be asked to confirm after this)");
        
        System.out.println("-------------------------------");
        System.out.println("Selected route: " + route);
        boolean confirmed = promptYesNo("Are you sure you want to remove this route?", true);
        
        if (!confirmed)
            return;
        
        int id = route.getId();
        
        // Kill him! :)
        String sql = "DELETE FROM schedule WHERE schedule_id="+id;
        connection.createStatement().execute(sql);
        
        System.out.println("-------------------------------");
        System.out.println("It is over! The route #" + id + " is gone.");
    }
}










